package com.gin.no_gay_alliance.viewmodel;

import com.gin.common.utils.TimeUtils;
import com.gin.nga.enums.ItemType;
import com.gin.nga.enums.TradeBit;
import com.gin.nga.response.field.item.ItemInfo;

/**
 * 道具model
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/7 15:42
 **/
public class ItemModel {
    /**
     * 道具id
     */
    public Long id;
    /**
     * 剩余数量
     */
    public Long count;
    /**
     * 价格描述
     */
    public String money;
    /**
     * 创建时间
     */
    public String time;
    /**
     * 类型
     */
    public ItemType type;
    /**
     * 名称
     */
    public String name;
    /**
     * 图标地址
     */
    public String icon;
    /**
     * 描述
     */
    public String description;
    /**
     * 购买限制
     */
    public String permissionBuyStore;
    public Integer buffId;
    public Integer buffValue0;
    /**
     * buff持续时间
     */
    public Integer buffLast;

    public ItemModel(ItemInfo info) {
        id = info.getId();
        count = info.getCount();
        time = TimeUtils.format(info.getTime(), TimeUtils.SHORT_FORMATTER);
        type = info.getType();
        name = info.getTypeInfo().getName();
        icon = info.getUrl();
        description = info.getTypeInfo().getDescription();
        permissionBuyStore = info.getTypeInfo().getPermissionBuyStore();
        buffId = info.getTypeInfo().getBuffId();
        buffValue0 = info.getTypeInfo().getBuffValue0();
        buffLast = info.getTypeInfo().getBuffLast();

        TradeBit tradeBit = info.getTradeBit();
        if (tradeBit != null) {
            // 铜币价格
            if (tradeBit == TradeBit.COPPER && info.getMoney() != null) {
                money = info.getMoney().toString();
            }
            // N币价格
            if (tradeBit == TradeBit.N) {
                money = info.getPrice() + " N币";
            }
        }
    }
}
